package districting;

import java.awt.Color;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Party implements Colorable {

   private String name;

   private String abbreviation;

   private Map<State, Double> toLaborState;

   private Map<State, Double> toCoalitionState;

   private Map<Division, Double> toLaborDiv;

   private Map<Division, Double> toCoalitionDiv;

   private Color color;

   private boolean isLabor;

   private boolean isCoalition;

   public Party(String name, String abbreviation, Color color) {
      this.name = name;
      this.abbreviation = abbreviation;
      this.color = color;
      this.toLaborState = new HashMap<State, Double>();
      this.toCoalitionState = new HashMap<State, Double>();
      this.toLaborDiv = new HashMap<Division, Double>();
      this.toCoalitionDiv = new HashMap<Division, Double>();
   }

   public Party(String name, String abbreviation, Color color, boolean isLabor,
         boolean isCoalition) {
      this.name = name;
      this.abbreviation = abbreviation;
      this.color = color;
      this.isLabor = isLabor;
      this.isCoalition = isCoalition;
      this.toLaborState = new HashMap<State, Double>();
      this.toCoalitionState = new HashMap<State, Double>();
      this.toLaborDiv = new HashMap<Division, Double>();
      this.toCoalitionDiv = new HashMap<Division, Double>();
   }

   /**
    * @return the color
    */
   public Color getColor() {
      return color;
   }

   /**
    * @param color
    *           the color to set
    */
   public void setColor(Color colour) {
      this.color = colour;
   }

   /**
    * @return the name
    */
   public String getName() {
      return name;
   }

   /**
    * @param name
    *           the name to set
    */
   public void setName(String name) {
      this.name = name;
   }

   /**
    * @return the abbreviation
    */
   public String getAbbreviation() {
      return abbreviation;
   }

   /**
    * @param abbreviation
    *           the abbreviation to set
    */
   public void setAbbreviation(String abbreviation) {
      this.abbreviation = abbreviation;
   }

   public void addPreferenceFlowState(State state, Double percentageToLabor,
         Double percentageToCoalition) {
      toLaborState.put(state, percentageToLabor);
      toCoalitionState.put(state, percentageToCoalition);
   }

   public void addPreferenceFlowToLaborDiv(Division div,
         Double percentageToLabor) {
      toLaborDiv.put(div, percentageToLabor);
   }

   public void addPreferenceFlowToCoalitionDiv(Division div,
         Double percentageToCoalition) {
      toCoalitionDiv.put(div, percentageToCoalition);
   }

   public Double getPercentToLabor(State state) {
      if (isLabor) {
         // System.out.println("Party, toLaborState, isLabor");
         return 1.0;
      } else if (isCoalition) {
         // System.out.println("Party, toLaborState, isCoalition");
         return 0.0;
      } else {
         // System.out.println("Party, toLaborState, neither");
         // System.out.println("party = " + name + ", partyAb = " +
         // abbreviation);
         return toLaborState.get(state);
      }
   }

   public Double getPercentToLabor(Division div) {
      if (isLabor) {
         // System.out.println("Party, toLaborState, isLabor");
         return 1.0;
      } else if (isCoalition) {
         // System.out.println("Party, toLaborState, isCoalition");
         return 0.0;
      } else {
         // System.out.println("Party, toLaborState, neither");
         // System.out.println("party = " + name + ", partyAb = " +
         // abbreviation);
         // System.out.println(toLaborDiv.get(div));
         return toLaborDiv.get(div);
      }
   }

   public Double getPercentToCoalition(State state) {
      if (isLabor) {
         return 0.0;
      } else if (isCoalition) {
         return 1.0;
      } else {
         return toCoalitionState.get(state);
      }
   }

   public Double getPercentToCoalition(Division div) {
      if (isLabor) {
         // System.out.println("Party, toCoalitionDiv, isLabor");
         return 0.0;
      } else if (isCoalition) {
         // System.out.println("Party, toCoalitionDiv, isCoalition");
         return 1.0;
      } else {
         // System.out.println("Party, toCoalitionDiv, isNeither");
         return toCoalitionDiv.get(div);
      }
   }

   /**
    * @return the isCoalition
    */
   public boolean isCoalition() {
      return isCoalition;
   }

   /**
    * @param isCoalition
    *           the isCoalition to set
    */
   public void setCoalition(boolean isCoalition) {
      this.isCoalition = isCoalition;
   }

   /**
    * @return the isLabor
    */
   public boolean isLabor() {
      return isLabor;
   }

   /**
    * @param isLabor
    *           the isLabor to set
    */
   public void setLabor(boolean isLabor) {
      this.isLabor = isLabor;
   }

   public void printPartyDetails() {
      System.out.println(name + ", Ab = " + abbreviation + ", isLabor = "
            + isLabor + ", isCoalition = " + isCoalition);
      // if(!isLabor && !isCoalition){
      for (State state : toLaborState.keySet()) {
         System.out.println(" in: " + state.getName() + " to Labor: "
               + toLaborState.get(state) + ", to Coalition: "
               + toCoalitionState.get(state));
      }
      // }
   }

}
